var path = require('path');
var webpack = require("webpack");
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;

// 模块导入
module.exports = {
    debug: true,
    // 入口文件地址，不需要写完，会自动查找
    entry: './src/main',
    // 输出
    output: {
        publicPath: 'build/',
        path: 'build/',
        filename: 'bundle.js'
    },
    // 加载器
    module: {
        // 加载器
        loaders: [
            // 解析.vue文件
            {
                test: /\.vue$/,
                loader: 'vue'
            },
            // 图片转化，小于8K自动转化为base64的编码
            {
                test: /\.(png|jpg|gif)$/,
                loader: 'file-loader?limit=8192&name=images/[hash].[ext]'
            },
            // use ! to chain loaders
            {
                test: /\.less$/,
                loader: 'style-loader!css-loader!less-loader'
            },
            {
                test: /\.scss$/,
                loaders: ['style','css','sass']
            },
            {
                test: /\.sass$/,
                loaders: ['style','css','sass']
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/,
                loader: 'file-loader?importLoaders=1&limit=1000&name=fonts/[name].[ext]'
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel',
                query: {compact: false}
            },
            {
                test: /\.json$/,
                loader: 'json'
            },
            //html模板编译
            {
                test: /\.(html|tpl)$/,
                loader: 'html-loader'
            }
        ]
    },
    babel: {
        presets: ['es2015', 'stage-0'],
        plugins: ['transform-runtime']
    },
    resolve: {
        // require时省略的扩展名，如：require('module') 不需要module.js
        extensions: ['', '.js', '.vue'],
        // 别名，可以直接使用别名来代表设定的路径以及其他
        alias: {
            filter: 'src/filters',
            components: 'src/components'
        }
    },
    plugins: [
        // 压缩 JavaScript
        // new uglifyJsPlugin({
        //     compress: {
        //         warnings: false
        //     }
        // }),
        // 全局Jquery
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery"
        })
    ]
};